package main

import (
	"backenddev/no4/gorms/models"
	"backenddev/no4/gorms/mysqldb"
	"crypto/md5"
	"fmt"

	"github.com/golang-module/carbon"
)

func main() {
	println("gorms")
	mysqldb.ConnectDb()

	//创建user
	user := &models.User{
		Username:  "testuser",
		Password:  MD5String("123456"),
		Email:     "user2@example.com",
		CreatedAt: carbon.Now().ToDateTimeString(),
	}
	result := mysqldb.MysqlDb.Create(user)
	if result.Error != nil {
		println("创建用户失败:", result.Error.Error())
	} else {
		println("创建用户成功:", user.Uid)
	}
}

// MD5String 返回字符串的 MD5 哈希（小写十六进制）
func MD5String(s string) string {
	h := md5.New()
	h.Write([]byte(s))
	return fmt.Sprintf("%x", h.Sum(nil))
}
